package com.android.djlmapp.adapter.dialog;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.model.kaika.SimNumInfo;

import java.util.ArrayList;

/**
 * Created by yucheng on 2018/3/3.
 */

public class GetSimNumAdapter extends BaseAdapter {
    private ArrayList<SimNumInfo.IccidListBean> simNum = new ArrayList<SimNumInfo.IccidListBean>();
    private Context context;

    public GetSimNumAdapter(Context context) {
        this.context = context;
    }

    public void setData(ArrayList<SimNumInfo.IccidListBean> simNum) {
        this.simNum = simNum;
        notifyDataSetChanged();
    }

    /**
     * 获取总数
     */
    @Override
    public int getCount() {

        if (simNum != null && simNum.size() > 0) {
            return simNum.size();
        } else {
            return 0;
        }
    }

    /**
     * 获取Item内容
     */
    @Override
    public SimNumInfo.IccidListBean getItem(int position) {
        return simNum.get(position);
    }

    /**
     * 获取Item的ID
     */
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        View view = View.inflate(context, R.layout.list_item_sim, null);
        TextView tv_sim = (TextView) view.findViewById(R.id.tv_sim);
        TextView selectNo = (TextView) view.findViewById(R.id.write_card_SelectNo);
        TextView cardType = (TextView) view.findViewById(R.id.write_card_card_type);
        LinearLayout selectNumLayout = (LinearLayout) view.findViewById(R.id.selectNumLayout);
        // 设置
        if ("1".equals(simNum.get(position).getType())) {
            selectNumLayout.setVisibility(View.GONE);
        } else {
            selectNumLayout.setVisibility(View.VISIBLE);
        }
        tv_sim.setText(simNum.get(position).getNum());
        selectNo.setText(simNum.get(position).getDuan());
        cardType.setText("(" + simNum.get(position).getType_name() + ")");
        return view;
    }
}
